package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.AppointDto;
import com.zzyl.dto.GetAppointPageDto;
import com.zzyl.entity.AppointCount;
import com.zzyl.service.CostomerAppointService;
import com.zzyl.utils.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CostomerAppointService costomerAppointService;
    /**
     * 查询取消数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Integer cancelCount = costomerAppointService.getCancelCount();
        return ResponseResult.success(cancelCount);
    }


    /**
     * 剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public ResponseResult getCountByTime(Long time){
        List<AppointCount> appointCountList= costomerAppointService.getCountByTime(time);
        return ResponseResult.success(appointCountList);
    }

    /**
     * 新增参观预约
     * @param dto
     * @return
     */
    @PostMapping()
    public ResponseResult appointControl(@RequestBody AppointDto dto){
        return  costomerAppointService.appointControl(dto);

    }

    /**
     * 参观预约分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public ResponseResult getPageAppoint(GetAppointPageDto dto){
        PageResponse pageResponse = costomerAppointService.getPageAppoint(dto);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public ResponseResult cancelAppoint(@PathVariable Long id){
        costomerAppointService.cancelAppoint(id);
        return ResponseResult.success("取消成功");
    }
}